package com.hiv.mapper;

import com.hiv.mapper.domain.Permission;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * permisson
 */
@Mapper
@Repository
public interface PermissionMapper {
    /** 增 */
    @Insert({"insert into permission(name, code, desc values (#{permission.name}, #{permission.code}, #{permission.desc})"})
    @Options(useGeneratedKeys = true, keyProperty = "permission.id")
    void insert(@Param("permission") Permission permission);

    /** 删 */
    @Delete("delete from permission where id = #{id} limit 1")
    void delete(@Param("id") long id);

    /** 查 */
    @Select("select * from permission where parent_id = #{parentId}")
    List<Permission> findByParentId(@Param("parentId") long parentId);

    @Select("select * from permission where id = #{id} limit 1")
    Permission findById(Long id);
}